package com.cheer.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cheer.entity.OaArticleEntity;
import com.cheer.entity.OaBannerEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 轮播图
 * 
 * @author cheer
 */
@Mapper
@Repository
public interface OaBannerDao extends BaseMapper<OaBannerEntity> {

    void incrSort(@Param("sort") Integer sort);

    void decrSort(@Param("sort") Integer sort);

    void incrSortRange(@Param("begin") Integer begin, @Param("end") Integer end);

    void decrSortRange(@Param("begin") Integer begin, @Param("end") Integer end);

    default IPage<OaBannerEntity> selectPage(Integer pageNum, Integer pageSize) {
        QueryWrapper<OaBannerEntity> queryWrapper = new QueryWrapper<OaBannerEntity>()
                .orderByAsc("sort");

        return selectPage(new Page<>(pageNum, pageSize), queryWrapper);
    }

    default OaBannerEntity getFirst() {
        return selectOne(new QueryWrapper<OaBannerEntity>()
                .eq("status", true)
                .orderByAsc("sort")
                .last("limit 1"));
    }

    default List<OaBannerEntity> selectListByOrder() {
        return selectList(new QueryWrapper<OaBannerEntity>()
                .eq("status", true)
                .orderByAsc("sort"));
    }
}
